﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Collections;

namespace PSE.Framework.Communication.Configuration
{
    public abstract class CommunicationConfigurationElementCollection : ConfigurationElementCollection, IList
    {
        #region IList Members

        public int Add(object value)
        {
            base.BaseAdd(value as ConfigurationElement);
            return this.Count - 1;
        }

        public void Clear()
        {
            base.BaseClear();
        }

        public bool Contains(object value)
        {
            return base.BaseIndexOf(value as ConfigurationElement) >= 0;
        }

        public bool Contains(string key)
        {
            return base.BaseGet(key) != null;
        }

        public int IndexOf(object value)
        {
            return base.BaseIndexOf(value as ConfigurationElement);
        }

        public void Insert(int index, object value)
        {
            base.BaseAdd(index, value as ConfigurationElement);
        }

        public bool IsFixedSize
        {
            get { return false; }
        }

        public new bool IsReadOnly
        {
            get { return base.IsReadOnly(); }
        }

        public void Remove(object value)
        {
            base.BaseRemoveAt(base.BaseIndexOf(value as ConfigurationElement));
        }

        public void RemoveAt(int index)
        {
            base.BaseRemoveAt(index);
        }

        public object this[int index]
        {
            get
            {
                return BaseGet(index);
            }
            set
            {
                base.BaseRemoveAt(index);
                base.BaseAdd(index, value as ConfigurationElement);
            }
        }

        public new object this[string key]
        {
            get
            {
                return BaseGet(key);
            }
            set
            {
                int index = base.BaseIndexOf(base.BaseGet(key));
                base.BaseRemove(key);
                base.BaseAdd(index, value as ConfigurationElement);
            }
        }

        #endregion
    }
}
